<template>
  <div class="tab-content">
    <div class="content-layout">
      <!--头部区域-->
      <div class="header" style="flex-shrink: 0">
        <div class="title-section">
          <h1 class="main-title">{{ currentDeviceName }}标定</h1>
          <h2 class="sub-title">确定[标定点位置]</h2>
          <div class="instruction-note">
            <span class="note-text">
              [注]请点击"批量定位"(非第一次出厂设置),设备自动运动至上次基准点位;
            </span>
            <span class="note-text">
              请现场人员检查,设备是否运动至正确的位置。如否,则手动调整设备至正确位置;
            </span>
            <span class="note-text">请点击"批量确认";</span>
          </div>
        </div>

        <!-- 全局操作按钮 -->
        <div class="global-actions">
          <el-button type="info" size="large" @click="handleBack">返回</el-button>
          <el-button type="primary" size="large" @click="handleBatchPositioning">
            批量定位
          </el-button>
          <el-button type="success" size="large" @click="handleBatchConfirm">批量确认</el-button>
          <el-button type="warning" size="large" @click="handleNextStep">下一步</el-button>
        </div>
      </div>

      <!-- 内容体 -->
      <div class="body">
        <component :is="currentComponent" class="status-panel" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed, defineAsyncComponent } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()

// 根据路由参数动态加载不同的组件
const currentComponent = computed(() => {
  const type = route.params.type as string

  type AsyncComponent = ReturnType<typeof defineAsyncComponent>

  const componentMap: Record<string, AsyncComponent> = {
    'alignment-control': defineAsyncComponent(() => import('./AlignmentControlPanel.vue')),
    'acc-calibration': defineAsyncComponent(() => import('./ACCCalibrationPanel.vue')),
    'accback-calibration': defineAsyncComponent(() => import('./ACCBackCalibrationPanel.vue')),
    'accangle-calibration': defineAsyncComponent(() => import('./ACCAngleCalibrationPanel.vue')),
    'ldw1-calibration': defineAsyncComponent(() => import('./LDW1CalibrationPanel.vue')),
    'ldwback1-calibration': defineAsyncComponent(() => import('./LDWBack1CalibrationPanel.vue')),
    'ldw2-calibration': defineAsyncComponent(() => import('./LDW2CalibrationPanel.vue')),
    'absorber-front-calibration': defineAsyncComponent(() => import('./AbsorberFrontCalibrationPanel.vue')),
    'absorber-back-calibration': defineAsyncComponent(() => import('./AbsorberBackCalibrationPanel.vue')),
    '360-calibration': defineAsyncComponent(() => import('./360CalibrationPanel.vue')),
    'fender-control-calibration': defineAsyncComponent(() => import('./FenderControlCalibrationPanel.vue'))
  }

  return componentMap[type] || componentMap['alignment-control']
})

// 根据路由参数获取当前设备名称
const currentDeviceName = computed(() => {
  const type = route.params.type as string
 
  const nameMap: Record<string, string> = {
    'alignment-control': '对中控制',
    'acc-calibration': 'ACC',
    'accback-calibration': 'ACCBack',
    'accangle-calibration': 'ACCAngle',
    'ldw1-calibration': 'LDW1',
    'ldwback1-calibration': 'LDWBack1',
    'ldw2-calibration': 'LDW2',
    'absorber-front-calibration': '吸波墙(前)',
    'absorber-back-calibration': '吸波墙(后)',
    '360-calibration': '360',
    'fender-control-calibration': '轮眉控制'
  }
  // 默认返回对中控制
  return nameMap[type] || '对中控制'
})

// 头部按钮处理函数
const handleBack = (): void => {
  router.push('/standard')
}

const handleBatchPositioning = (): void => {
  ElMessage.success('批量定位已执行')
}

const handleBatchConfirm = (): void => {
  ElMessage.success('批量确认已执行')
}

const handleNextStep = (): void => {
  ElMessage.info('进入下一步')
}
</script>

<style scoped>
.tab-content {
  width: 100%;
  height: 100%;
  padding: 0 20px 20px 20px;
}

/* 头部区域样式 */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
  background: white;
  padding: 24px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  min-height: 120px;
}

.title-section {
  flex: 1;
}

.main-title {
  font-size: 24px;
  font-weight: 600;
  color: #333;
  margin: 0 0 16px 0;
}

.sub-title {
  font-size: 20px;
  font-weight: 500;
  color: #666;
  margin: 0 0 16px 0;
  text-align: center;
}

.instruction-note {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.note-text {
  color: #e74c3c;
  font-size: 14px;
  line-height: 1.5;
}

.global-actions {
  display: flex;
  gap: 12px;
}

.body {
  background: white;
  padding: 0;
  position: relative;
  display: flex;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  flex: 1;
  overflow: hidden;
}

.status-panel {
  width: 100%;
  height: 100%;
}
</style>
